package com.yx.shop.web.controller;

import cn.dsna.util.images.ValidateCode;
import com.yx.shop.common.Const;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname CreateCodeContrtoller
 * @Description TODO:
 * @Date 2021/05/06 20:55
 * @Created by yx
 */
@WebServlet("/code")
public class CreateCodeContrtoller extends BaseServlet{


    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //1.获取验证码对象
        ValidateCode validateCode = new ValidateCode(120,35,4,20);
        //2.存验证码
        String codes = validateCode.getCode();
        request.getSession().setAttribute(Const.CODES,codes);
        //3.响应验证码
        validateCode.write(response.getOutputStream());
    }
}
